package com.ljf.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljf.admin.POJO.SysMenu;
import com.ljf.admin.POJO.SysRoleMenu;
import com.ljf.admin.mapper.SysMenuMapper;
import com.ljf.admin.service.SysMenuService;
import com.ljf.admin.service.SysRoleMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: lijinfeng
 * @Date: 2022/4/21
 * @Description 描述:
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {

    @Resource
    private SysMenuMapper sysMenuMapper;

    @Resource
    private SysRoleMenuService sysRoleMenuService;

    @Override
    public int updateBatch(List<SysMenu> list) {
        return baseMapper.updateBatch(list);
    }
    @Override
    public int updateBatchSelective(List<SysMenu> list) {
        return baseMapper.updateBatchSelective(list);
    }
    @Override
    public int batchInsert(List<SysMenu> list) {
        return baseMapper.batchInsert(list);
    }

    @Override
    public List<SysMenu> getListByUserId(Long userId) {
        return sysMenuMapper.getListByUserId(userId);
    }

    @Override
    @Transactional
    public void deleteMenuByUser(Long menuId, Long userId) {
        sysMenuMapper.deleteById(menuId);
        QueryWrapper<SysRoleMenu> qw = new QueryWrapper<>();
        qw.eq("menu_id",menuId);
        sysRoleMenuService.remove(qw);
    }


}
